package com.cloud.lan.api.manage;

import com.cloud.lan.api.dto.req.MmsTemplateReq;
import com.cloud.lan.entity.base.BaseResponse;
import com.cloud.lan.entity.base.ListResponse;
import com.cloud.lan.integration.submail.mms.entity.MmsSendReq;
import com.cloud.lan.integration.submail.mms.entity.MmsSendRes;
import com.cloud.lan.integration.submail.mms.entity.MmsTemplateModel;
import com.cloud.lan.integration.submail.mms.service.MmsSendService;
import com.cloud.lan.integration.submail.sms.entity.SmsSendModel;
import com.cloud.lan.service.sms.MmsTemplateManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by zhouquan on 2022/4/4.
 */
@RestController
@RequestMapping(value = {"/v1/manage/mms/template"}, method = {RequestMethod.GET, RequestMethod.POST}, produces = {"application/json"})
public class MmsTemplateManageApi {

    @Autowired
    private MmsTemplateManageService manageService;
    @Autowired
    private MmsSendService mmsSendService;

    @RequestMapping("manageList")
    public ListResponse<Object> manageList(MmsTemplateModel model){
        return manageService.manageList(model);
    }

    @RequestMapping("merge")
    public BaseResponse<Object> merge(@RequestBody MmsTemplateReq templateReq){
        return manageService.merge(templateReq);
    }

    @RequestMapping("del")
    public BaseResponse<Object> del(MmsTemplateModel model){
        return manageService.del(model);
    }

    @RequestMapping("multixsend")
    public BaseResponse<Object> multixsend(@RequestBody MmsSendReq sendReq){
        List<MmsSendRes> resList = mmsSendService.multixsend(sendReq);
        BaseResponse response = BaseResponse.success();
        response.setData(resList);
        return response;
    }

    @RequestMapping("send")
    public BaseResponse<Object> send(@RequestBody SmsSendModel sendModel){
        MmsSendReq sendReq = new MmsSendReq();
        sendReq.setTemplateId(sendModel.getTemplateId());
        List<SmsSendModel> modelList = new ArrayList<>();
        modelList.add(sendModel);
        sendReq.setModelList(modelList);
        List<MmsSendRes> resList = mmsSendService.multixsend(sendReq);
        BaseResponse response = BaseResponse.success();
        response.setData(resList);
        return response;
    }
}
